
package com.woniuxy.main.mapper;

import com.woniuxy.main.pojo.Room;
import com.woniuxy.main.pojo.RoomType;
import com.woniuxy.main.provider.RoomProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoomMapper {
	//查询所有房间
	@SelectProvider(type =RoomProvider.class,method ="loadRoomSql" )
	@Results({
		@Result(id = true,column = "room_id",property = "room_id"),
		@Result(column = "roomnum",property = "roomnum"),
		@Result(column = "status",property = "status"),
		@Result(column = "location",property = "location"),
		@Result(column = "cut",property = "cut"),
		@Result(column = "hot",property = "hot"),
		@Result(column = "flag",property = "flag"),
		@Result(column = "phone",property = "phone"),
		@Result(column = "roomtype_id",property = "roomtype",one = @One(
				select = "com.woniuxy.main.mapper.RoomMapper.getRoomTypeByRoomTypeId"

				))
	})
	public List<Room> loadAllRoom();


	@Select("select type from roomtype where roomtype_id =#{roomtype_id}")
	public RoomType getRoomTypeByRoomTypeId(int roomtype_id);

	//筛选查询房间

	@SelectProvider(type =RoomProvider.class,method ="provideSql" )
	@Results({
		@Result(id = true,column = "room_id",property = "room_id"),
		@Result(column = "roomnum",property = "roomnum"),
		@Result(column = "status",property = "status"),
		@Result(column = "location",property = "location"),
		@Result(column = "cut",property = "cut"),
		@Result(column = "hot",property = "hot"),
		@Result(column = "flag",property = "flag"),
		@Result(column = "phone",property = "phone"),
		@Result(column = "roomtype_id",property = "roomtype",one = @One(
				select = "com.woniuxy.main.mapper.RoomTypeMapper.getRoomTypeById"

				))
	})
	public List<Room> searchRoom(Room room);

	//添加房间
	//还要添加设备表
	@Insert("insert into room(roomnum,roomtype_id,status,location,cut,) values(#{roomnum},#{roomtype_id},#{status},#{location},#{cut})")
	public boolean addRoom(Room room);


	//房间的移除
	@Update("update room set flag=1 where room_id=#{room_id}")
	public boolean delectRoom(int room_id);

	//房间的修改
	//状态的修改，可住，维修中。
	@Update("update room set status=#{status} where room_id=#{room_id} and flag=0")
	public boolean updateStatus(int status,int room_id);

	//折扣的修改
	@Update("update room set cut=#{cut} where flag=0")
	public boolean updateCut(double cut);


	/**查询:根据订单id集合  查询出所有对应的房间号
	 * @param orderIdList
	 * @return
	 */
	@Select({
			"<script>",
			"select",
			"*",
			"from orderlist",
			"where order_id in",
			"<foreach collection='orderIdList' item='id' open='(' separator=',' close=')'>",
			"#{id}",
			"</foreach>",
			"</script>"
	})
	List<Room> findRoomByOrderId(@Param("orderIdList") List<Integer> orderIdList);

	/**查询:根据房间状态 查询所有房间
	 * @param status
	 * @return
	 * @throws Exception 全部
	 */
	@Select("select * from room where status=#{status} and flag=0")
	@Results({
			@Result(id = true,column = "room_id",property = "room_id"),
			@Result(column = "roomnum",property = "roomnum"),
			@Result(column = "status",property = "status"),
			@Result(column = "location",property = "location"),
			@Result(column = "cut",property = "cut"),
			@Result(column = "hot",property = "hot"),
			@Result(column = "flag",property = "flag"),
			@Result(column = "phone",property = "phone"),
			@Result(column = "roomtype_id",property = "roomtype",one = @One(
					select = "com.woniuxy.main.mapper.RoomTypeMapper.getRoomTypeById"

			))
	})
	public List<Room> findRoomByStatus(Integer status)throws Exception;

	/**查询:根据房间id 精准查询房间
	 * @param room_id
	 * @return
	 * @throws Exception 全部
	 */
	@Select("select * from room where room_id=#{room_id} and flag=0")
	@Results({
			@Result(id = true,column = "room_id",property = "room_id"),
			@Result(column = "roomnum",property = "roomnum"),
			@Result(column = "status",property = "status"),
			@Result(column = "location",property = "location"),
			@Result(column = "cut",property = "cut"),
			@Result(column = "hot",property = "hot"),
			@Result(column = "flag",property = "flag"),
			@Result(column = "phone",property = "phone"),
			@Result(column = "roomtype_id",property = "roomtype",one = @One(
					select = "com.woniuxy.main.mapper.RoomTypeMapper.getRoomTypeById"

			))
	})
	public Room findRoomByID(Integer room_id)throws Exception;

}

